<?php

class GuestbookAction extends AdminbaseAction{

	public function _initialize(){

		parent::_initialize();
	}

	public function index(){

		$list = M('guestbook')->where()->order('create_time desc')->select();
		$this->list = $list;
		$this->display();
	}

	/**
	 * 回复管理留言
	 * @return [type] [description]
	 */
	public function edit(){
		$map['id'] = I('get.id');
		$info = M('guestbook')->where($map)->find();
		$this->info = $info;
		$this->display();
	}


	public function handleEdit(){

		$map['id'] = I('post.id');
		$data['name'] = I('post.name');
		$data['email'] = I('post.email');
		$data['phone'] = I('post.phone');
		$data['qq'] = I('post.qq');
		$data['content'] = I('post.content');
		$data['reply'] = I('post.reply');
		$data['ip'] = I('post.ip');
		$data['create_time'] = strtotime(I('post.create_time'));
		$data['status'] = I('post.status');
		$res = M('guestbook')->where($map)->save($data);
		if($res){
			$this->success('保存成功',U('guestbook/index'));
		}else{
			$this->error('保存失败，数据未更改');
		}
	}
	/**
	 * 删除留言
	 * @return [type] [description]
	 */
	public function delete(){
		$map['id'] = I('get.id');
		$res = M('guestbook')->where($map)->delete();
		if($res){
			redirect(U('admin/guestbook/index'));
		}else{
			$this->error('删除失败');
		}
	}


}